package com.lovegu.collection;

import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;

/**
 * @author 老顾
 * @title: TestConcurrence
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/9/24 10:59
 */
public class TestConcurrence {
    public static void main(String[] args) throws InterruptedException {
        ArrayList<Integer> list = new ArrayList<>();
        CountDownLatch countDownLatch = new CountDownLatch(200);
        for (int i = 0; i < 200; i++) {
            new Thread(()->{
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                list.add(1);
                countDownLatch.countDown();
            }).start();
        }
        countDownLatch.await();
        System.out.println(list.size());
    }
}
